<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/
  defined('_JEXEC') or die('Retricted Access');
  rendfield_JS();
  JRequest::setVar( 'hidemainmenu', 1 );
  global $jbconfig;
  JFilterOutput::objectHTMLSafe( $this->item );
  JHTML::_('behavior.tooltip');
?>
<?php JHTML::_('behavior.modal'); ?>
<script type="text/javascript" language="javascript">
//<![CDATA[
siteurl = '<?php echo JURI::base();  ?>';
function submitbutton(pressbutton) {
	var form = document.adminForm;
	
	var numericExpression = /^[0-9]+$/;
	var numericExpression1 = /^[0-9]+\.[0-9]{1,2}$/;
	max_location_selection = <?php echo  $jbconfig['posts']->get('maximum_locations',3);?>;
	max_category_selection = <?php echo  $jbconfig['posts']->get('maximum_cats',3);?>;
    if(pressbutton == 'apply' || pressbutton == 'save'){
    	sum_location = cal_number_selection('location_id',child_location_id);
		sum_category = cal_number_selection('cat_id',child_cat_id)
    	//Check location selection
		if (sum_location > max_location_selection)
		{
			alert("<?php echo JText::_('Your selected location is out of allow selection number.').' ('.JText::_('Limited is ').$jbconfig['posts']->get('maximum_locations',3).' selections)'; ?>");
			return;
		}
		
		var user_id = form.user_id.value;
		if ((user_id == ""))
		{
			alert("<?php echo JText::_( 'Customer ID could not be empty', true ); ?>");
			form.user_id.focus();
			return;
		}
		else 
		{
			if ($('user_error').value=='1')
			{
				alert('<?php echo JText::_('This user is not exist'); ?>');
				return;
			}
			if(user_id !="")
			{
				if(user_id.match(numericExpression)||user_id.match(numericExpression1))
				{
					$submitform =1;
				}
				else
				{
					alert("<?php echo JText::_( 'Customer ID must be numeric', true ); ?>");
					form.user_id.focus();
					return;
				}
			}
			
		}
		
		//Check category selection
		if (sum_category > max_category_selection)
		{
			alert("<?php echo JText::_('Your selected category is out of allow selection number.').' ('.JText::_('Limited is ').$jbconfig['posts']->get('maximum_cats',3).' selections)'; ?>");
			return;
		}
		        
		obj_apply_type = document.getElementById('apply_type1');
		if (obj_apply_type!=null)
		if (typeof($('apply_type1'))!='undifine' && $('apply_type1').checked){
			if (typeof(form.direct_url) != 'undefined'){
				if($('direct_url').value==''){
					alert('<?php echo JText::_('Direct URL for apply could not be empty'); ?>');
					return;
				}
			}
		}
    }
    
    form.task.value = pressbutton;
    form.submit();
	
}
function validate_userid(){
	var name_userid = $("check_username");
	var userid = $('user_id');
	
	if(userid.value=='')	{
		name_userid.innerHTML = '<img src="' + siteurl + 'components/com_jajobboard/images/not.png" alt="" title="" /><span style="font-weight: bold;color: red;"><?php echo JText::_('Please enter Custommer ID'); ?></span>';
		return false;
	}
	else{
		$('check_username').innerHTML = '<img src="' + siteurl + 'components/com_jajobboard/images/loading.gif" alt="" title="" />';
		var url = 'index.php?option=com_jajobboard&view=jatransactions&task=check_user&user_id='+escape(userid.value);
		new Ajax(url, {method:'get', onComplete:updateValidate_userid}).request();	
	}
}

function updateValidate_userid(text){
	if(text=='Yeah')
	{
		$('check_username').innerHTML = '<img title="" alt="" src="' + siteurl + 'components/com_jajobboard/images/ok.png"/>';
		$('user_error').value = 0;
	}
	else
	{
		$('check_username').innerHTML = '<img src="' + siteurl + 'components/com_jajobboard/images/not.png" alt="" title="" /><span style="font-weight: bold;color: red;">' + text + '</span>';
		$('user_error').value = 1;
	}

}

function select_direct_url(is_checked)
{
	var form = document.adminForm;
	s_direct_url = document.getElementById('s_direct_url');
	if (is_checked)
	{
		
		s_direct_url.setStyle('display','');
	}
	else
	{
		s_direct_url.setStyle('display','none');
	}
	
}
function assign_user(user_id)
{
	document.getElementById('user_id').value = user_id;	
	document.getElementById('user_id').focus();	
	document.getElementById('sbox-window').close();
}

window.addEvent('domready', function() {
    if( typeof( $('effected_date')) != "undefined" && typeof( $('expiry_date')) != "undefined" ){                
        /*$('effected_date').addEvent('keyup', function(event){
            var expiry_date = document.getElementById('expiry_date');
            
            if(expiry_date.value == ""){
                expiry_date.value = document.getElementById('effected_date').value;
            }
        });*/
    }
});

//]]>
</script>

<form name="adminForm" action="index.php" method="post" enctype="multipart/form-data">
    <table width="100%">
		<tr>
		
		<td width="80%" valign="top">
			<div style="width:100%;">
				<fieldset>			
					<legend><?php echo JText::_('Job Information');?></legend>
					<table class="admintable">
			            <?php
			            $k=0;
			            for($i = 0, $n = count($this->fieldlist); $i < $n; $i++ )
			            if ($this->fieldlist[$i]->field_name!='direct_url')
			            {
			                $field = $this->fieldlist[$i];
			                $field_name = $field->field_name;
			                
			                if($field->field_type=='SEPERATOR'){?>	
				                </table>
								</fieldset>   		                
				                <fieldset>
									<legend><?php echo JText::_($field->label);?></legend>
									<table class="admintable">
			               <?php }elseif (!in_array($field->field_name,array('views','ordering','id'))){ ?>        
				                <tr class="row<?php echo $k; ?>">
				                    <td class="key" width="20%"><?php  echo JText::_($field->label); ?></a>
				                    </td>
				                    <td width="80%">
				                        <?php
				                        
				                        echo rendfield($this->item, $field, false, false);
				                        if ($field->field_name=='user_id') {
				                        ?>
				                        <a class="modal" rel="{handler: 'iframe', size: {x: 650, y: 375}}" href="index.php?option=com_jajobboard&view=jatransactions&layout=element_user&tmpl=component" title="Select an User">(<?php echo JText::_('Select employer'); ?>)</a>
				                        <span id="check_username"> &nbsp;</span>
				                        <?php } ?>
				                        
				                    </td>
				                </tr>
			                <?php }
			            }?>
			           </table>
				</fieldset>    
			</div>
		</td>
	</tr>
	</table>
	<input type="hidden" name="user_error" id="user_error" value="" />
	<input type="hidden" name="cid" value="<?php echo $this->item->id; ?>" />
	<input type="hidden" name="option" value="<?php echo $this->option; ?>" />
	<input type="hidden" name="view" value="jajobs" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="boxchecked" value="1" />
		
	<?php echo JHTML::_( 'form.token' ); ?>	
 </form>
